package experiment;

import java.io.*;

public class ExperimentThree {
//    public static void main(String[] args) {
//        String fileName = "D:\\memo.txt";
//        String line;
//        //创建一个 memo.txt 文件
//        try {
//            FileWriter writer = new FileWriter(fileName);
//            writer.write("Hello!\n");
//            writer.write("welcome!\n");
//            writer.write("Today is Thursday!\n");
//            writer.write("Wish you happy everyday~");
//            writer.close();
//        } catch (IOException iox) {
//            System.out.println("问题出现在：" + fileName);
//        }
//        //读取 memo.txt 文件中的数据
//        try{
//            BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName));
//            line = bufferedReader.readLine();
//            while(line != null){
//                System.out.println(line);
//                line = bufferedReader.readLine();
//            }
//            bufferedReader.close();
//        }catch(IOException iox){
//            System.out.println("问题出现在：" + fileName);
//        }
//    }
//}
    public static void main(String[] args) {
        Complex c1 = new Complex(5,6);
        Complex c2 = new Complex(2,3);
        Complex c3 = new Complex();
        c3 = c1.complexAdd(c2);

        System.out.println(c1.ToString());
        System.out.println(c2.ToString());
        System.out.println(c3.ToString());
    }
    static class Complex {
        private int RealPart;
        private int ImaginPart;
        public Complex() {
            RealPart = 0;
            ImaginPart = 0;
        }
        public Complex(int r, int i) {
            RealPart = r;
            ImaginPart = i;
        }
        public Complex complexAdd(Complex a) {
            Complex b = new Complex();
            b.RealPart = RealPart + a.RealPart;
            b.ImaginPart = ImaginPart + a.ImaginPart;
            return b;
        }
        public String ToString(){
            return RealPart + "+" + ImaginPart + "i";
        }
    }
}


